import socket


def main():
    # 服务器地址和端口号
    host = '121.41.40.95'  # 可以是服务器的 IP 地址
    port = 2621         # 服务器的端口号
    message = 'user=huangyq@flyinggnss.com;pwd=fly888888;cmd=full;lat=30;lon=120;'

    # 创建一个 socket 对象
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        # 连接到服务器
        client_socket.connect((host, port))
        print(f"Connected to server {host} on port {port}")

        # 发送数据到服务器
        client_socket.sendall(message.encode('utf-8'))
        print(f"Sent: {message}")

        # 从服务器接收数据
        data = client_socket.recv(10240)
        print(f"Received: {data}")

    except socket.error as e:
        print(f"Socket error: {e}")

    finally:
        # 关闭连接
        client_socket.close()
        print("Connection closed")

if __name__ == "__main__":
    main()